package com.project.base.controller;

import com.project.base.service.UserService;
import com.project.core.auth.LoginDTO;
import com.project.core.auth.LoginRes;
import com.project.core.auth.UserDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * @author mengxj
 */
@Api("人员信息")
@RestController
@RequestMapping("user")
public class UserController {

    @Resource
    private UserService userService;

    @ApiOperation("登录接口")
    @PostMapping("login")
    public LoginRes login(@RequestBody LoginDTO login){
        return this.userService.login(login);
    }

    @ApiOperation("刷新token")
    @GetMapping("refresh-token")
    public LoginRes refreshToken(HttpServletRequest request){
        return this.userService.refreshToken(request);
    }

    @ApiOperation("创建用户")
    @PostMapping("save")
    public void save(@RequestBody @Valid UserDTO user){
        this.userService.save(user);
    }

    @ApiOperation("退出登录")
    @GetMapping("logout")
    public void logout(){
        this.userService.logout();
    }
}
